<!doctype html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>RabbitMQ 高级特性详解</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        
        .card-hover {
            transition: all 0.3s ease;
        }
        
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
        }
        
        .code-block {
            background: #1e1e1e;
            color: #d4d4d4;
            border-radius: 8px;
            padding: 1.5rem;
            overflow-x: auto;
            font-family: 'Consolas', 'Monaco', monospace;
            font-size: 0.9rem;
            line-height: 1.6;
            box-shadow: 0 4px 6px rgba(0,0,0,0.1);
        }
        
        .section-title {
            position: relative;
            padding-left: 1rem;
        }
        
        .section-title::before {
            content: '';
            position: absolute;
            left: 0;
            top: 50%;
            transform: translateY(-50%);
            width: 4px;
            height: 100%;
            background: linear-gradient(180deg, #667eea 0%, #764ba2 100%);
            border-radius: 2px;
        }
        
        .quote-box {
            background: linear-gradient(135deg, #f5f7fa 0%, #e9ecef 100%);
            border-left: 4px solid #667eea;
            padding: 1.5rem;
            border-radius: 0 8px 8px 0;
            box-shadow: 0 2px 8px rgba(0,0,0,0.05);
        }
        
        .feature-card {
            background: white;
            border-radius: 12px;
            padding: 2rem;
            box-shadow: 0 4px 20px rgba(0,0,0,0.08);
            transition: all 0.3s ease;
        }
        
        .feature-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 8px 30px rgba(0,0,0,0.12);
        }
        
        .mermaid {
            background: white;
            padding: 2rem;
            border-radius: 8px;
            box-shadow: 0 4px 12px rgba(0,0,0,0.08);
        }
        
        .drop-cap {
            float: left;
            font-size: 4rem;
            line-height: 1;
            font-weight: 700;
            margin-right: 0.5rem;
            margin-top: -0.2rem;
            color: #667eea;
            font-family: 'Noto Serif SC', serif;
        }
        
        .highlight-text {
            background: linear-gradient(120deg, #f093fb 0%, #f5576c 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            font-weight: 600;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20">
        <div class="container mx-auto px-6">
            <div class="text-center">
                <h1 class="text-5xl md:text-6xl font-bold mb-6 animate-pulse">
                    <i class="fas fa-network-wired mr-4"></i>RabbitMQ 高级特性
                </h1>
                <p class="text-xl md:text-2xl mb-8 opacity-90">深入理解消息队列的核心机制与最佳实践</p>
                <div class="flex justify-center space-x-8 text-lg">
                    <div class="flex items-center">
                        <i class="fas fa-skull-crossbones mr-2"></i>
                        <span>死信队列</span>
                    </div>
                    <div class="flex items-center">
                        <i class="fas fa-clock mr-2"></i>
                        <span>延时队列</span>
                    </div>
                    <div class="flex items-center">
                        <i class="fas fa-check-circle mr-2"></i>
                        <span>消息确认</span>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="container mx-auto px-6 py-12">
        <!-- 死信队列 Section -->
        <section class="mb-16">
            <h2 class="text-4xl font-bold mb-8 section-title text-gray-800">
                <i class="fas fa-skull mr-3 text-purple-600"></i>死信队列
            </h2>
            
            <div class="feature-card mb-8">
                <h3 class="text-2xl font-semibold mb-4 text-gray-700">
                    <i class="fas fa-question-circle mr-2 text-purple-500"></i>什么是死信队列
                </h3>
                <div class="quote-box">
                    <p class="text-gray-700 leading-relaxed mb-4">
                        <span class="drop-cap">一</span>般来说，producer将消息投递到queue中，consumer从queue取出消息进行消费，但某些时候由于特定的原因导致queue中的某些消息无法被消费，这样的消息如果没有后续的处理，就变成了死信(Dead Letter)，所有的死信都会放到死信队列中，统一的处理。
                    </p>
                    <p class="text-gray-700 leading-relaxed mb-4">
                        "死信"消息会被RabbitMQ进行特殊处理，如果配置了死信队列信息，那么该消息将会被丢进死信队列中，如果没有配置，则该消息将会被丢弃。
                    </p>
                </div>
                
                <div class="mt-6 grid md:grid-cols-3 gap-4">
                    <div class="bg-green-50 p-4 rounded-lg border border-green-200">
                        <i class="fas fa-check-circle text-green-600 text-2xl mb-2"></i>
                        <h4 class="font-semibold text-green-800">正常消费</h4>
                        <p class="text-sm text-gray-700">手动ack → MQ删除消息</p>
                    </div>
                    <div class="bg-yellow-50 p-4 rounded-lg border border-yellow-200">
                        <i class="fas fa-exclamation-triangle text-yellow-600 text-2xl mb-2"></i>
                        <h4 class="font-semibold text-yellow-800">消费者报错</h4>
                        <p class="text-sm text-gray-700">没有ack → 待应答状态</p>
                    </div>
                    <div class="bg-red-50 p-4 rounded-lg border border-red-200">
                        <i class="fas fa-times-circle text-red-600 text-2xl mb-2"></i>
                        <h4 class="font-semibold text-red-800">手动nack</h4>
                        <p class="text-sm text-gray-700">配置死信队列 → 发送到DLX</p>
                    </div>
                </div>
            </div>

            <div class="feature-card mb-8">
                <h3 class="text-2xl font-semibold mb-4 text-gray-700">
                    <i class="fas fa-list-ul mr-2 text-purple-500"></i>死信队列的来源
                </h3>
                <div class="grid md:grid-cols-3 gap-6">
                    <div class="bg-gradient-to-br from-purple-50 to-pink-50 p-6 rounded-lg">
                        <i class="fas fa-ban text-3xl text-purple-600 mb-3"></i>
                        <h4 class="font-semibold text-gray-800 mb-2">消息被拒绝</h4>
                        <p class="text-sm text-gray-600">basic.reject或basic.nack且requeue=false</p>
                    </div>
                    <div class="bg-gradient-to-br from-blue-50 to-cyan-50 p-6 rounded-lg">
                        <i class="fas fa-hourglass-end text-3xl text-blue-600 mb-3"></i>
                        <h4 class="font-semibold text-gray-800 mb-2">消息TTL过期</h4>
                        <p class="text-sm text-gray-600">消息存活时间超过设定值</p>
                    </div>
                    <div class="bg-gradient-to-br from-green-50 to-teal-50 p-6 rounded-lg">
                        <i class="fas fa-inbox text-3xl text-green-600 mb-3"></i>
                        <h4 class="font-semibold text-gray-800 mb-2">队列达到最大长度</h4>
                        <p class="text-sm text-gray-600">队列满了，无法再添加数据</p>
                    </div>
                </div>
            </div>

            <div class="feature-card">
                <h3 class="text-2xl font-semibold mb-4 text-gray-700">
                    <i class="fas fa-code mr-2 text-purple-500"></i>配置死信队列
                </h3>
                <pre class="code-block"><code>@Configuration
public class RabbitMQConfig {

    // 声明业务Exchange
    @Bean
    public TopicExchange businessExchange(){
        return new TopicExchange("businessExchange");
    }

    // 声明业务队列A
    @Bean
    public Queue businessQueue(){
        Map&lt;String, Object&gt; args = new HashMap&lt;&gt;();
        // x-dead-letter-exchange 声明当前队列绑定的死信交换机
        args.put("x-dead-letter-exchange", "deadLetterExchange");
        // x-dead-letter-routing-key 声明当前队列的死信路由key
        args.put("x-dead-letter-routing-key", "dle.err");

        return new Queue("businessQueue",true,false,false,args);
    }

    // 声明死信Exchange
    @Bean
    public TopicExchange deadLetterExchange(){
        return new TopicExchange("deadLetterExchange");
    }
}</code></pre>
            </div>
        </section>

        <!-- 延时队列 Section -->
        <section class="mb-16">
            <h2 class="text-4xl font-bold mb-8 section-title text-gray-800">
                <i class="fas fa-clock mr-3 text-blue-600"></i>延时队列
            </h2>
            
            <div class="feature-card mb-8">
                <h3 class="text-2xl font-semibold mb-4 text-gray-700">
                    <i class="fas fa-info-circle mr-2 text-blue-500"></i>什么是延时队列
                </h3>
                <div class="quote-box">
                    <p class="text-gray-700 leading-relaxed">
                        延迟队列存储的对象肯定是对应的延时消息，所谓"延时消息"是指当消息被发送以后，并不想让消费者立即拿到消息，而是等待指定时间后，消费者才拿到这个消息进行消费。普通队列中的元素总是等着希望被早点取出处理，而延时队列中的元素则是希望被在指定时间得到取出和处理。
                    </p>
                </div>
            </div>

            <div class="feature-card">
                <h3 class="text-2xl font-semibold mb-4 text-gray-700">
                    <i class="fas fa-cog mr-2 text-blue-500"></i>TTL机制与延时队列
                </h3>
                <div class="mermaid">
                    <script type="text/javascript">
                        mermaid.initialize({ startOnLoad: true });
                    </script>
                    <div class="mermaid">
                        graph LR
                            A[生产者] -->|发送消息| B[延时队列]
                            B -->|TTL过期| C[死信交换机]
                            C -->|路由| D[死信队列]
                            D -->|消费| E[消费者]
                            
                            style A fill:#667eea,stroke:#333,stroke-width:2px,color:#fff
                            style B fill:#f093fb,stroke:#333,stroke-width:2px,color:#fff
                            style C fill:#f5576c,stroke:#333,stroke-width:2px,color:#fff
                            style D fill:#4facfe,stroke:#333,stroke-width:2px,color:#fff
                            style E fill:#43e97b,stroke:#333,stroke-width:2px,color:#fff
                    </div>
                </div>
                
                <div class="grid md:grid-cols-2 gap-6 mt-8">
                    <div class="bg-gradient-to-r from-blue-50 to-indigo-50 p-6 rounded-lg">
                        <h4 class="font-semibold text-gray-800 mb-3">
                            <i class="fas fa-envelope mr-2 text-blue-600"></i>给消息设置TTL
                        </h4>
                        <p class="text-sm text-gray-